function [dinamicTotal, bestStageTracking]=bestDinamicRange(main, filterType, wa, wp, waMAS, waMENOS, wpMAS, wpMENOS)

dinamicTotal=100000;  % ponele
n=main.stageAmount;
i=1;
while i<n
    for j=1:n-1
        aux1=main.stageTracking{j,1};
        aux2=main.stageTracking{j,2};
        aux3=main.plotTracking{j,1};
        aux4=main.plotTracking{j,2};
        aux5=main.plotTracking{j,3};
        aux6=main.plotTracking{j,4};
        main.stageTracking{j,1}=main.stageTracking{j+1,1};
        main.stageTracking{j,2}=main.stageTracking{j+1,2};
        main.plotTracking{j,1}=main.plotTracking{j+1,1};
        main.plotTracking{j,2}=main.plotTracking{j+1,2};
        main.plotTracking{j,3}=main.plotTracking{j+1,3};
        main.plotTracking{j,4}=main.plotTracking{j+1,4};
        main.stageTracking{j+1,1}=aux1;
        main.stageTracking{j+1,2}=aux2;
        main.plotTracking{j+1,1}=aux3;
        main.plotTracking{j+1,2}=aux4;
        main.plotTracking{j+1,3}=aux5;
        main.plotTracking{j+1,4}=aux6;
        
        [dinamicLossDown, dinamicLossUp, stageLow, stageUp]=dinamicLoss (main, filterType, wa, wp, waMAS, waMENOS, wpMAS, wpMENOS);
        dinamicTotalAux=dinamicLossDown+dinamicLossUp;
        if (dinamicTotalAux<dinamicTotal)
            dinamicTotal=dinamicTotalAux;
            bestStageTracking=main.stageTracking;
        end
    end
    i=i+1;
end
end